#ifndef __LIB_KERNEL_IO_H
#define __LIB_KERNEL_IO_H
#endif

#include "stdint.h"

static inline void outb(uint8_t data, uint16_t port){								//Write data to 8 bits port.
	asm volatile ("outb %b0, %w1"::"a"(data), "d"(port));
}

/*static inline void outw(uint16_t data, uint16_t port){								//Write data to 16 bits port.
	asm volatile ("outw %w0, %w1"::"a"(data), "d"(port));
}
*/
static inline uint8_t inb(uint16_t port){	
	uint8_t data;								//
	asm volatile ("inb %w1, %b0":"=a"(data):"d"(port));
	return data;
}

/*static inline inw(uint16_t data, uint16_t port){
	asm volatile ("inw %w1, %w1":"=a"(data):"d"(port));
}*/

static inline void outsw(uint16_t port, const void* addr, uint32_t word_cnt){			//Write word_cnt words from ds:esi to destinate port.
	asm volatile ("cld; rep outsw":"+S"(addr), "+c"(word_cnt):"d"(port));
}

static inline void insw(uint16_t port, const void* addr, uint32_t word_cnt){			//Read word_cnt words form port to ds:esi.
	asm volatile ("cld; rep insw":"+D"(addr), "+c"(word_cnt):"d"(port):"memeory");
} 